﻿using System;
using UnityEngine;
using System.Collections;

public class Basics5 : MonoBehaviour
{
	void Update()
	{
		if (networkView.isMine)
		{
			Vector3 moveDirection = new Vector3(Input.GetAxis("Vertical"),
				0f, Input.GetAxis("Horizontal"));
			float speed = 30f;
			transform.Translate(speed * moveDirection * Time.deltaTime);
		}
	}

	private void Awake()
	{
		if (!networkView.isMine)
		{
			enabled = false;
		}
	}

	private void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
	{
		if (stream.isWriting)
		{
			Vector3 pos = transform.position;
			//"Encode" it, and send it
			stream.Serialize(ref pos);
		}
		else
		{
			Vector3 posReceive = Vector3.zero;
			//"Decode" it and receive it
			stream.Serialize(ref posReceive);
			transform.position = posReceive;
		}
	}
}